using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyBoom1 : MonoBehaviour
{
    SeqAction boomAction=new(){intervalTime=1f/3f}; 

    Sprite[] sprites;

    void Awake()
    {
        sprites=new Sprite[]{
            Constant.Sprites["敌-爆炸1-1"],
            Constant.Sprites["敌-爆炸1-2"],
            Constant.Sprites["敌-爆炸1-3"],
        };
    }

    void FixedUpdate()
    {
        boomAction.Update((SeqAction seq)=>{
            if(TryGetComponent(out SpriteRenderer renderer)){
                int index=seq.seqNo-1;
                if(index<sprites.Length){
                    renderer.sprite=sprites[index];
                }else{
                    seq.done=true;
                }
            }
        });
        if(boomAction.done){
            Destroy(gameObject);
        }
    }
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.TryGetComponent(out Damageable damageable))
        {
            damageable.Damage(gameObject, 1);
        }
    }

}
